import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { NzMessageService, NzModalRef, NzModalService } from 'ng-zorro-antd';

@Injectable()
export class UtilService {
  readImgUrl = 'http://static.lessonplan.cn/';
  constructor(
    private http: HttpClient,
    private modal: NzModalService,
    private message: NzMessageService
  ) { }

  comfirm(text: string, callback): void {
    let confirmModal: NzModalRef;
    confirmModal = this.modal.confirm({
      nzTitle: text,
      nzOnOk: () => {
        callback();
      }
    });
  }

  remind(type: string, text: string): void {
    this.message.create(type, text);
  }

  getUserInfo(): Promise<any> {
    // return new Promise((resolve, reject) => {
    //   resolve({status: 1, userGuid: '8a525c72-9fb1-b12f-9332-8c138c2e85f2'})
    // })
    return this.http.get(`/api/userInfo`).toPromise().then(res => {
      return res;
    })
  }

  logout(): Promise<any> {
    return this.http.get(`/logout`).toPromise().then(res => {
      return res;
    })
  }
}
